﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using WiimoteLib;

namespace TayoukiNameSpace
{
    public partial class TayoukiMenu : Form
    {
        Wiimote wm = new Wiimote();
       
        GameForm gameForm;

        private bool btnPressed;

        public TayoukiMenu()
        {
            InitializeComponent();
            btnPressed = false;
            //Thread miniGameThread = new Thread(new ThreadStart(startMiniGame));
            //miniGameThread.Start();
            //f = new Form1(this);
        }

        public void startMiniGame(){
            //finish
    }


        private void TayoukiMenu_Load(object sender, EventArgs e)
        {
            wm.WiimoteChanged += new EventHandler<WiimoteChangedEventArgs>(wm_WiimoteChanged);
            wm.Connect();            
            wm.SetReportType(InputReport.IRAccel, true);
            wm.SetLEDs(true, false, false, true);

            shapeGameBtn.Focus();
        }

        private void shapeGameBtn_Click(object sender, EventArgs e)
        {
            
        }

        private void clkGameBtn_Click(object sender, EventArgs e)
        {
            gameForm = new GameForm();           
            gameForm.Show();
        }

        
        private void dirGameBtn_Click(object sender, EventArgs e)
        {
            
        }

        private void wm_WiimoteChanged(object sender, WiimoteChangedEventArgs args)
        {
            WiimoteState wms = args.WiimoteState;

            if (wms.ButtonState.Down)
            {
                if (!btnPressed)
                {
                    SendKeys.SendWait("{DOWN}");
                }
                btnPressed = true;
            }

            else if (wms.ButtonState.Up)
            {
                if (!btnPressed)
                { 
                    SendKeys.SendWait("{UP}"); 
                }
                btnPressed = true;
            }

            else if (wms.ButtonState.A)
            {
                SendKeys.SendWait("{ENTER}");
            }

            else
            {
                btnPressed = false;
            }
        }

        private void Canvas_FormClosing(object sender, FormClosingEventArgs e)
        {
            wm.SetLEDs(false, false, false, false);
            wm.Disconnect();
            wm.Dispose();
        }

       
        
    }
}
